package com.epoint.androidphone.mobileoa.ui.mail;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.epoint.androidmobile.bizlogic.mail.task.Mail_GetList_Task;
import com.epoint.androidmobile.core.phoneutil.Service;
import com.epoint.androidphone.R;
import com.epoint.androidphone.mobileoa.ui.superview.SuperPhonePage;

/**
 * @author liyc
 * @time @2013-5-5 下午11:43:11
 * @annomation
 */
public class MailMain extends SuperPhonePage {

	String[] lvtitle = new String[] { "收件箱", "发件箱", "草稿箱", "回收站", "接收的任务邮件",
			"发出的任务邮件", "写邮件" };
	ListView lv;
	CateAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addContentViewAndTitle(R.layout.webinfocommonlist, getIntentViewTitle());
		lv = (ListView) findViewById(R.id.lv);
		lv.setOnItemClickListener(this);

		CateAdapter adapter = new CateAdapter();
		lv.setAdapter(adapter);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO 自动生成的方法存根
		super.onItemClick(parent, view, position, id);
		//收件箱
		if (position == 0) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.INBOX_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			startActivity(intent);
			//发件箱
		} else if (position == 1) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.OUTBOX_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			startActivity(intent);
			//草稿箱
		} else if (position == 2) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.DRAFTS_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			startActivity(intent);
			//回收站
		} else if (position == 3) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.RECYCLE_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			startActivity(intent);
			//收到的任务邮件
		} else if (position == 4) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.TASK_INBOX_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			intent.putExtra("NeedTaskMonitor", Mail_GetList_Task.TASK_TODO_TYPE);
			startActivity(intent);
			//发送的任务邮件
		} else if (position == 5) {
			Intent intent = new Intent(this, MailBoxListView.class);
			intent.putExtra("boxType", Mail_GetList_Task.TASK_OUTBOX_TYPE);
			intent.putExtra("viewtitle", lvtitle[position]);
			intent.putExtra("NeedTaskMonitor", Mail_GetList_Task.TASK_TODO_TYPE);
			startActivity(intent);
			//写邮件
		} else if (position == 6) {
			Service.intentViewWithTitle(this, MailSendView.class,
					lvtitle[position]);
		}
	}

	class CateAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return lvtitle.length;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			LayoutInflater mInflater = LayoutInflater.from(getContext());
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.catelayout, null);
				holder.tvInfo = (TextView) convertView
						.findViewById(R.id.tvInfo);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			holder.tvInfo.setText(lvtitle[position]);
			return convertView;
		}
	}

	class ViewHolder {
		public TextView tvInfo;
	}
}
